<?php 
namespace app\model;

use think\Model;
use think\Db;

class Order extends Model{
	public static function getListByPage($num){
		$res = Db::name('Order o')
				->field("order_id,u.user_name,o.commodity_id,o.commodity_num,c.commodity_name
					,co.courier_name,order_price,o.gmt_create")
				->join("commodity c","o.commodity_id = c.commodity_id")
				->join("user u","o.user_id = u.user_id")
				->join("courier co","o.courier_id = co.courier_id","left")
				->where([
					"is_done"=>0,
					"o.is_delete"=>0,
				])
				->paginate($num);
		return $res;
	}

	public static function getDoneByPage($num){
		$res = Db::name('Order o')
				->field("order_id,u.user_name,o.commodity_id,o.commodity_num,c.commodity_name
					,co.courier_name,order_price,o.gmt_create")
				->join("commodity c","o.commodity_id = c.commodity_id")
				->join("user u","o.user_id = u.user_id")
				->join("courier co","o.courier_id = co.courier_id","left")
				->where([
					"is_done"=>1,
					"o.is_delete"=>0,
				])
				->paginate($num);
		return $res;
	}

	public static function getDeleteByPage($num){
		$res = Db::name('Order o')
				->field("order_id,u.user_name,o.commodity_id,o.commodity_num,c.commodity_name
					,co.courier_name,order_price,o.gmt_create")
				->join("commodity c","o.commodity_id = c.commodity_id")
				->join("user u","o.user_id = u.user_id")
				->join("courier co","o.courier_id = co.courier_id","left")
				->where("o.is_delete",1)
				->paginate($num);
		return $res;
	}

	// 按用户获取购买商品
	public static function getBuyCommodityByUser($user_id){
		$res = Db::name('order o')
				->field('order_id,co.commodity_id,co.commodity_name,order_price,o.commodity_num,picture_address,o.gmt_create')
				->join("commodity co","o.commodity_id = co.commodity_id")
				->where([
					"o.user_id" => $user_id,
					"o.is_delete" => 0,
				])
				->paginate();
		return $res;
	}

	// 获取订单信息
	public static function getInfo($id){
		$res = Db::name('order o')
				->field('order_id,co.commodity_addr,co.commodity_id,co.commodity_name,order_price,o.commodity_num,picture_address,o.gmt_create,category_name')
				->join("commodity co","o.commodity_id = co.commodity_id")
				->join("category ca","co.category_id = ca.category_id")
				->where([
					"o.order_id" => $id,
					"o.is_delete" => 0,
				])
				->find();
		return $res;
	}

	// 获取订单信息
	public static function getMyOrder($courier_id,$num){
		$res = Db::name('Order o')
				->field("order_id,u.user_name,o.commodity_id,o.commodity_num,c.commodity_name
					,co.courier_name,order_price,o.gmt_create")
				->join("commodity c","o.commodity_id = c.commodity_id")
				->join("user u","o.user_id = u.user_id")
				->join("courier co","o.courier_id = co.courier_id","left")
				->where([
					"o.courier_id"=>$courier_id,
					"is_done"=>0,
					"o.is_delete"=>0,
				])
				->paginate($num);
		return $res;
	}

	// 获取订单信息
	public static function getMyDoneOrder($courier_id,$num){
		$res = Db::name('Order o')
				->field("order_id,u.user_name,o.commodity_id,o.commodity_num,c.commodity_name
					,co.courier_name,order_price,o.gmt_create")
				->join("commodity c","o.commodity_id = c.commodity_id")
				->join("user u","o.user_id = u.user_id")
				->join("courier co","o.courier_id = co.courier_id","left")
				->where([
					"o.courier_id"=>$courier_id,
					"is_done"=>1,
					"o.is_delete"=>0,
				])
				->paginate($num);
		return $res;
	}
}

 ?>